package no.somenvm.dreamplanners

import com.gitee.planners.api.PlannersAPI
import com.gitee.planners.api.ProfileAPI
import org.bukkit.entity.Player
import priv.seventeen.artist.dreampainter.api.DreamPainterGlowingAPI
import priv.seventeen.artist.dreampainter.api.DreamPainterScreenAPI
import priv.seventeen.artist.dreampainter.api.screen.IScreen
import priv.seventeen.artist.dreampainter.event.ClientCustomPacketEvent
import taboolib.common.platform.event.SubscribeEvent
import taboolib.common.platform.function.console

object SkillUI{
    lateinit var ui: IScreen

    @SubscribeEvent
    fun e(e: ClientCustomPacketEvent){
        console().sendMessage(e.id)
        if (e.id != "DreamPlanners") return
        when(e.getData(0).string){
            "select_skill" -> {
                e.getData(1).string?.let {
                    updateInfo(e.player,it)
                }
            }
        }
    }


    fun updateSkillList(player : Player){
        val key = mutableListOf<String>()
        val name = mutableListOf<String>()
        ui.runScript(player,"var.skillD = Dict[]")
        ProfileAPI.get(player.uniqueId).getRegistrySkill().toMap().forEach {
            DreamPainterScreenAPI.sendIconItemStack(player,it.value.id,it.value.immutable.icon)
            key += it.value.id
            name += it.value.immutable.id
            ui.runScript(player,"var.skillD.put('${it.value.id}','${it.value.immutable.id}')")
        }
        console().sendMessage("发送key: &e$key")
        console().sendMessage("发送name: &e$name")
    }

    fun updateInfo(player: Player,key: String){
        ui.runScript(player,"var.skillHover = $key")
        ui.runScript(player,"var.info = List[]")
        ProfileAPI.get(player.uniqueId).getSkill(key).get().immutable.icon?.itemMeta?.lore?.forEach {
            ui.runScript(player,"var.info.add('$it')")
        }
    }
}